/**
 * Created by gaotonglin on 2018/07/24
 * 公共方法
 */

export default new class Method {
  constructor() {
  }

  //vue observer 对象转换成普通对象
  parseVueObject(obj) {
    return JSON.parse(JSON.stringify(obj))
  }
  
  //将数字或字符串数字转换成金额显示并显示两位小数
  toMoney(num) {
    if (num == '' || num == undefined || num == null) {
      num = 0
    }
    num = parseFloat(num);
    num = num.toFixed(2);
    num = parseFloat(num);
    num = num.toLocaleString();
    var s = num.split('.')[1]
    if (s == undefined) {
      num += '.00'
    }
    if (s != undefined && s.length == 1) {
      num += '0'
    }
    return num;
  }

  toMoneyKW(num) {
    if (num == '' || num == undefined || num == null) {
      num = 0
    }
    num = parseFloat(num);
    if (num >= 10000000) {
      num = (num / 10000000).toFixed(2) + 'kw'
    } else if (num >= 10000) {
      num = (num / 10000).toFixed(2) + 'w'
    } else if (num >= 1000) {
      num = (num / 1000).toFixed(2) + 'k'
    } else {
      num = num.toFixed(2)
    }
    return num;
  }
}